<template>
    <div class="top">
        <div class="nav">
            <h5>可趁管理 / 添加课程</h5>
            <button @click="jumpClass()">返回</button>
        </div>
        <div class="center">
            <h4>请填写课程相关信息</h4>
            <br>
            <div class="conter-main">
                <h4>课程名称:</h4>
                <input placeholder="请输入名称" clearable class="ipt" v-model="person._name" />
            </div>
            <div class="conter-main conter-pict">
                <h4>课程封面:</h4>
                <div class="picture" model-value="cover">
                   <div v-if="Flg.flg1">
                        <div class="up-picture">+</div>
                        <p>上传照片</p>
                   </div>
                   <!-- <input type="text" else placeholder="请输入照片路径" /> -->
                </div>
                <p>只能上传jpg/png文件,并不超过500kb</p>
            </div>
            <br>
            <div class="conter-main" style="margin-top:30px">
                <h4>课程状态:</h4>
                <el-switch v-model="value2" class="mb-2"
                    style="--el-switch-on-color: #13ce66; --el-switch-off-color: #ff4949" active-text="上线状态"
                    inactive-text="下线状态" />
            </div>
            <div class="conter-main">
                <h4>课程价格:</h4>
                <input placeholder="请输入名称" clearable class="ipt" v-model="person.price" />
            </div>
            <div class="conter-main">
                <h4>手机号码:</h4>
                <textarea placeholder="请输入内容" class="txt" v-model="person.phone"></textarea>
            </div>
            <div class="conter-main">
                <h4>讲师介绍:</h4>
                <textarea placeholder="请输入内容" class="txt" v-model="person.teacher_init"></textarea>
            </div>
            <div class="conter-main catalogue">
                <h4>课程目录:</h4>
                <div>
                    <span>+</span>
                    <span>新增</span>
                </div>
            </div>
            <button class="btn" @click="addUser()">立即添加</button>
            <button class="cancel" @click="cancel()">取消</button>
        </div>
    </div>
</template>

<script >
import { addClassCourse } from '../api/api.js'
import { ref } from 'vue'
export default {
    name: 'cao',
    setup() {
        const person = ref({
            serial_number:' ',
            _name: ' ',
            cover: ' ',
            state_s: ' ',
            price: ' ',
            brief: ' ',
            teacher_init: ' ',
            phone:' ',
            up_tim: ' ',
            dispose_tim:' ',
            up_tim:'',
            sech_tim: ' ',
        })
        const par = ref({});
        const Flg = ref({
            flg1: true
        })
        const person_list = ref([])
        const value2 = ref(true)
        return {
            person,
            person_list,
            value2,
            Flg,
            par
        }
    },
    mounted(){
        //  this.par = this.$route.query
        // console.log(this.$route.query);
        this.par = this.$route.params;
        console.log(this.par)
    },
    methods: {
        // 跳转
        jumpClass() {
            this.$router.push('/classCoure')
        },
        // 取消
        cancel(){
            this.person = {
                serial_number:'',
                name: '',
                cover: '',
                state_s: '',
                price: '',
                brief: '',
                teacher_init: '',
                up_time: '',
                phone: '',
                sech_time: ''
            }
        },
        addUser() {
            // 当前时
            let yy = new Date().getFullYear();
            let mm = new Date().getMonth()+1;
            let dd = new Date().getDate();
            let NowTime = yy+"."+mm+"."+dd
            // console.log(NowTime)
            this.person.up_tim = NowTime
            // console.log(this.person.up_tim)

            // 销量
            let random1 = Math.random()*(5*100)+10
            Number(random1)
            
            this.person.serial_number = random1
            console.log(this.person.serial_number)

            // 状态
            this.person.state_s = this.value2
            this.person_list = this.person
            const add_data = this.person_list

            addClassCourse(add_data)
                .then(res => {
                    this.person = {
                        serial_number:'',
                        name: '',
                        cover: '',
                        state_s: '',
                        price: '',
                        brief: '',
                        teacher_init: '',
                        up_time: '',
                        phone: '',
                        sech_time: ''
                    }
                    console.log(res)
                }
                )
                .catch(err => {
                    console.log(err)
                })
        }
    }
}
</script>
<style scoped>
* {
    margin: 0;
    padding: 0;
    list-style: none;
    text-align: left;
}

.top {
    width: calc(100% - 60px);
    height: 100vh;
    padding: 35px 30px;
    background-color: #f0f0f0;
}

.nav {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    margin-bottom: 30px;
}

.nav>button {
    margin-left: 83.5%;
    width: 60px;
    height: 30px;
    text-align: center;
    border: none;
    background: #38a28a;
    color: #fff;
    border-radius: 5px;
    cursor: pointer;
}

.conter-main {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    width: 100%;
    height: 40px;
    margin-bottom: 30px;
    line-height: 50px;
}

.ipt {
    width: 300px;
    height: 30px;
    border: 1px solid #e9ecf0;
    outline: none;
    font-size: 12px;
    padding-left: 5px;
    margin-left: 15px;
    font-weight: 700;
}

.txt {
    width: 300px;
    height: 40px;
    line-height: 40px;
    border: 1px solid #e9ecf0;
    font-weight: 700;
    outline: none;
    font-size: 12px;
    padding-left: 5px;
    margin-left: 15px;
    resize: none;
}

.center {
    width: calc(100% - 60px);
    height: calc(100% - 120px);
    padding: 30px 30px;
    background-color: #fff;
}

.conter-pict>p {
    width: 100%;
    padding-left: 80px;
    font-size: 12px;
}

.up-picture {
    text-align: center;
    font-size: 50px;
    color: #898989;
}

.picture {
    text-align: center;
    width: 90px;
    height: 90px;
    background-color: #fafafa;
    font-size: 14px;
    border: 1px dashed #898989;
    margin-top: -10px;
    margin-left: 15px;
}

.picture>div>p {
    text-align: center;
    margin-top: -15px;
}

.top>button {
    background-color: #38a28a;
    color: white;
    width: 70px;
    height: 30px;
    float: right;
    border: none;
    border-radius: 5px;
    text-align: center;
}

.catalogue>div {
    width: 70px;
    height: 30px;
    border: 1px solid #38a28a;
    border-radius: 5px;
    margin-left: 15px;
    text-align: center;
    line-height: 30px;
    font-size: 14px;
}

.catalogue>div>span:nth-child(1) {
    font-size: 18px;
    margin-right: 5px;
}

.btn {
    background-color: #38a28a;
    color: white;
    width: 70px;
    height: 30px;
    border: none;
    border-radius: 4px;
    text-align: center;
    margin-left: 85px;
}

.cancel {
    width: 60px;
    height: 30px;
    text-align: center;
    margin-left: 15px;
    background: #fff;
    border: 1px solid #e9ecf0;
    border-radius: 4px;
}
</style>
